package Test3;

import java.util.*;

public class Test3 {
    public static void main(String[] args) {
        //定义Map集合，用Student对象作为key，用字符串(此表示表示学生的住址)作为value
        Map<Student,String> student = new HashMap<Student, String>();
        student.put(new Student("刘咏",24),"杭州");
        student.put(new Student("刘凯",24),"杭州");
        student.put(new Student("小聪聪",23),"杭州");
        student.put(new Student("阿潘",24),"毕节");
        //利用四种方式遍历Map集合中的内容，格式：key:value
        Set<Student> set1 = student.keySet();
        for (Student s1: set1 ) {
            System.out.println(s1+":"+student.get(s1));
        }
        System.out.println("---------------------------------------");

        Set<Map.Entry<Student,String>> set2 = student.entrySet();
        for(Map.Entry<Student,String> s2 : set2){
            System.out.println(s2);
        }
        System.out.println("---------------------------------------");

        Iterator<Map.Entry<Student,String>> it = student.entrySet().iterator();
        while (it.hasNext()){
            Map.Entry<Student,String> entry = it.next();
            System.out.println(entry.getKey()+":"+entry.getValue());
        }
        System.out.println("---------------------------------------");
        student.forEach((Student,String) -> {
            System.out.println(student);
        });
    }
}
